﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EC_Agent.TransportClass;
using System.Data;
using EC_Agent.Models;
using System.Data.SqlClient;

namespace EC_Agent
{
    public partial class Transport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Search_Click(object sender, EventArgs e)
        {
            TransportWS ts = null;
            DataSet dataset = new NhaCungCapModels().ListUrlNhaCungCap("Transport");
            DataSet dsALL = new DataSet();
            foreach (DataRow Row in dataset.Tables[0].Rows)
            {
                ts = new TransportWS(Row["WS"].ToString());
                ts.CookieContainer = new System.Net.CookieContainer();
                ts.DangNhap(Row["UsernameA"].ToString(), Row["PasswordA"].ToString());
                string dichvu = Convert.ToString(ddlDichVu.Text);

                ArrayToDataTable exec = new ArrayToDataTable();
                DataTable rTable = null;

                DataSet dsBangGia = new DataSet();
                rTable = exec.ConvertArrayToDataTable(ts.BangGiaTrongNgay(dichvu));
                dsBangGia.Tables.Add(rTable);
                DataTable BangGia = dsBangGia.Tables[0];

                BangGia.Columns.Add("CompanyUrl", System.Type.GetType("System.String"));
                BangGia.Columns.Add("Company", System.Type.GetType("System.String"));
                int j = 0;
                foreach (DataRow BangGiaRow in BangGia.Rows)
                {
                    BangGia.Rows[j]["CompanyUrl"] = Row["WS"].ToString();
                    BangGia.Rows[j]["Company"] = Row["TenNCC"].ToString();
                    j++;
                }
                dsALL.Merge(dsBangGia);

            }
            dvTransport.DataSource = dsALL;
            dvTransport.DataBind();

        }
    }
}